{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 时间序列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "import os\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>年份</th>\n",
       "      <th>啤酒产量\n",
       "（万千升）</th>\n",
       "      <th>人均GDP\n",
       "（元）</th>\n",
       "      <th>煤炭占能源消费\n",
       "总量的比重(%)</th>\n",
       "      <th>居民消费价格指数（上年=100）</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2000</td>\n",
       "      <td>2231.3</td>\n",
       "      <td>7857.7</td>\n",
       "      <td>69.2</td>\n",
       "      <td>100.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2001</td>\n",
       "      <td>2288.9</td>\n",
       "      <td>8621.7</td>\n",
       "      <td>68.3</td>\n",
       "      <td>100.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2002</td>\n",
       "      <td>2402.7</td>\n",
       "      <td>9398.1</td>\n",
       "      <td>68.0</td>\n",
       "      <td>99.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     年份  啤酒产量\\n（万千升）  人均GDP\\n（元）  煤炭占能源消费\\n总量的比重(%)  居民消费价格指数（上年=100）\n",
       "0  2000       2231.3      7857.7               69.2             100.4\n",
       "1  2001       2288.9      8621.7               68.3             100.7\n",
       "2  2002       2402.7      9398.1               68.0              99.2"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 贾俊平<<统计学(第六版)>> 时间序列节例题数据\n",
    "\n",
    "db = '/home/lidong/Datasets/'\n",
    "data_df = pd.read_excel(os.path.join(db, \"Statistics/beer-gdp-coal-cpi.xls\"))\n",
    "data_df[0:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 暴力列重命名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Yt</th>\n",
       "      <th>Beer</th>\n",
       "      <th>GDP</th>\n",
       "      <th>Coal</th>\n",
       "      <th>CPI</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2000</td>\n",
       "      <td>2231.3</td>\n",
       "      <td>7857.7</td>\n",
       "      <td>69.2</td>\n",
       "      <td>100.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2001</td>\n",
       "      <td>2288.9</td>\n",
       "      <td>8621.7</td>\n",
       "      <td>68.3</td>\n",
       "      <td>100.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2002</td>\n",
       "      <td>2402.7</td>\n",
       "      <td>9398.1</td>\n",
       "      <td>68.0</td>\n",
       "      <td>99.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Yt    Beer     GDP  Coal    CPI\n",
       "0  2000  2231.3  7857.7  69.2  100.4\n",
       "1  2001  2288.9  8621.7  68.3  100.7\n",
       "2  2002  2402.7  9398.1  68.0   99.2"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_df.columns = ['Yt', 'Beer', 'GDP', 'Coal', 'CPI']\n",
    "data_df[:3] # data_df['Yt'][0:3] or data_df.Yt[0:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 修改年份列的值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Yt</th>\n",
       "      <th>Beer</th>\n",
       "      <th>GDP</th>\n",
       "      <th>Coal</th>\n",
       "      <th>CPI</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>2231.3</td>\n",
       "      <td>7857.7</td>\n",
       "      <td>69.2</td>\n",
       "      <td>100.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2288.9</td>\n",
       "      <td>8621.7</td>\n",
       "      <td>68.3</td>\n",
       "      <td>100.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>2402.7</td>\n",
       "      <td>9398.1</td>\n",
       "      <td>68.0</td>\n",
       "      <td>99.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Yt    Beer     GDP  Coal    CPI\n",
       "0   0  2231.3  7857.7  69.2  100.4\n",
       "1   1  2288.9  8621.7  68.3  100.7\n",
       "2   2  2402.7  9398.1  68.0   99.2"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data_df['Yt'] = data_df['Yt'].map(lambda x: x - 2000)\n",
    "data_df[:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 做图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
